﻿<UserControl x:Class="SfdClient.View.LogsView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300" xmlns:my="clr-namespace:SfdClient.Converter"
             xmlns:Entities="clr-namespace:Sfd.Entities;assembly=Sfd.Entities">
    <UserControl.Resources>
        <my:LogEntryToImageConverter x:Key="LogEntryToImageConverter" />
    </UserControl.Resources>
    <UserControl.DataContext>
        <Binding Path="LogsViewModel" Source="{StaticResource locator}"/>
    </UserControl.DataContext>
    <Grid>
        <ListView ItemsSource="{Binding LogEntries}" ItemTemplate="{DynamicResource ResourceKey=dtLogEntry}">
            <ListView.Resources>
                <DataTemplate x:Key="dtIcon" DataType="{x:Type Entities:LogEntry}">
                    <Image Source="{Binding Path=Category, Converter={StaticResource LogEntryToImageConverter}}" Width="20" Height="16" Margin="0"/>
                </DataTemplate>     
                <DataTemplate x:Key="dtTime" DataType="{x:Type Entities:LogEntry}">
                    <TextBlock Text="{Binding Path=Time.UtcNow, StringFormat={}{0:HH:mm:ss}}"/>
                </DataTemplate>
                <DataTemplate x:Key="dtLogEntry" DataType="{x:Type Entities:LogEntry}">
                    <TextBlock Text="{Binding Path=Message}"/>
                </DataTemplate>
                </ListView.Resources>
            <ListView.ContextMenu>
                <ContextMenu>
                    <MenuItem Command="{Binding ClearLogCommand, Mode=OneWay}" Header="{Binding [LogsView_Vider], Source={StaticResource localizer}}">
                        <MenuItem.Icon>
                            <Image Source="{DynamicResource ClearLogs}" Width="16" />
                        </MenuItem.Icon>
                    </MenuItem>
                </ContextMenu>
                </ListView.ContextMenu>
            
            <ListView.View>
                <GridView>
                    <GridView.Columns>
                        <GridViewColumn CellTemplate="{DynamicResource ResourceKey=dtIcon}" Width="28"/>
                        <GridViewColumn Header="{Binding [LogsView_Heure], Source={StaticResource localizer}}" CellTemplate="{DynamicResource ResourceKey=dtTime}"/>
                        <GridViewColumn Header="{Binding [LogsView_Message], Source={StaticResource localizer}}" CellTemplate="{DynamicResource ResourceKey=dtLogEntry}" Width="400"/>
                    </GridView.Columns>
                </GridView>
            </ListView.View>
        </ListView>
    </Grid>
</UserControl>
